package it.softphone.cmc.server;


import it.softphone.commons.spring.config.BaseWebConfigSupport;

import org.apache.commons.configuration.ConfigurationException;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.plugin.context.AnnotationDrivenConfig;

@Configuration
@AnnotationDrivenConfig
public class MainConfig extends BaseWebConfigSupport {
	
	@Bean public org.apache.commons.configuration.Configuration baseConfig() {
		
		try {
			return super.getBaseConfig();
			
		} catch (ConfigurationException e) {
			
			logger.error( "error reading configuration", e );
		}
		
		return null;
	}
	
/*
	@Bean(lazy=Lazy.TRUE) public SecurityAccountService accountService() throws GeneralSecurityException {
		
		try {
			SecurityAccountServiceFactory factory = SecurityAccountServiceFactory.getSecurityAccountServiceFactory();
			
			return factory.newSecurityAccountService(null);
			
		} catch (GeneralSecurityException e) {
			logger.error( "error loading  SecurityAccountService", e );
			throw e;
		}
		
		
	}
	
	@Autowired(required=true) EntityManagerService entityManagerService;
	//@Autowired(required=true) EventManagerService eventManagerService;
	
	@Bean(lazy=Lazy.FALSE) public ScriptingService scriptingService() {
		ScriptingService service = null;
		try {
			
			service = ScriptingServiceFactory.getScriptingService(baseConfig());
						
			service.put( "EntityManager", entityManagerService);
			//service.put( "EventManager", eventManagerService);
			service.put( "Log", logger);
			
		} catch (ScriptException e) {
			
			logger.error( "error getting script service", e );
		}
		
		return service;
	}
*/
}
